#include <Fl/fl_ask.H>

#include "WubiUI.h"
#include <windows.h>

int main(){

    // 创建允许普通用户访问的安全描述符
    SECURITY_ATTRIBUTES saMutex = {0};
    SECURITY_DESCRIPTOR sdMutex;
    InitializeSecurityDescriptor(&sdMutex, SECURITY_DESCRIPTOR_REVISION);
    SetSecurityDescriptorDacl(&sdMutex, TRUE, NULL, FALSE);

    saMutex.nLength = sizeof(SECURITY_ATTRIBUTES);
    saMutex.lpSecurityDescriptor = &sdMutex;
    saMutex.bInheritHandle = FALSE;

    // 创建互斥体检测程序实例, 防止重复启动
    HANDLE hMutex = CreateMutex(&saMutex, TRUE, "Local\\MengYuUIMutex");
    DWORD last_error = GetLastError();
    if (hMutex == NULL ||
        last_error == ERROR_ALREADY_EXISTS ||
        last_error == ERROR_ACCESS_DENIED)
    {
        if (hMutex)
        {
            ReleaseMutex(hMutex);
            CloseHandle(hMutex);
        }
        return 0;
    }

    // 设置UTF-8编码支持
    Fl::set_font(FL_SYMBOL, "SimSun"); // 使用宋体显示中文

    WubiUI wubi_ui;
    wubi_ui.init();
    wubi_ui.show();

    return Fl::run(); 
}
